package com.biz.service.auth.impl;

import javax.annotation.Resource;

import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.biz.dao.common.GenericDAO;
import com.biz.dto.user.UserDTO;
import com.biz.service.auth.LoginService;
import com.framework.core.exception.LoginException;

@Service("loginServiceImpl")
public class LoginServiceImpl  implements LoginService {
	@Resource(name="genericDAOImpl")
	private GenericDAO<UserDTO, String> genericDAO; 
	
	public void insert(UserDTO userDTO) throws LoginException{
		try {
			genericDAO.insert(userDTO);
		} catch (DataAccessException e) {
			throw new LoginException("新增用户异常", e);
		}
	}

	public UserDTO query(String id) throws LoginException {
		return genericDAO.query(UserDTO.class, id);
		
	}
	
	@Transactional(noRollbackFor=NullPointerException.class)
	public void transactionalMethod() throws LoginException {
		UserDTO user = new UserDTO();
		user.setUserid(1);
		user.setUsername("admin0003");
		genericDAO.insert(user);
		System.out.println("1:"+genericDAO.query(UserDTO.class, "0003"));
		throw new NullPointerException();
		
	}

}
